<!DOCTYPE HTML>
<html class="no-js">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>商之联后台管理系统</title>
  <meta name="description" content="这是一个 table 页面">
  <meta name="keywords" content="table">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="{:C('SUPPLIER_ADMIN_IMG')}favicon.png"> <link rel="apple-touch-icon-precomposed" href="{:C('SUPPLIER_ADMIN_IMG')}app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="{:C('SUPPLIER_ADMIN_CSS')}amazeui.min.css"/>
  <link rel="stylesheet" href="{:C('SUPPLIER_ADMIN_CSS')}admin.css">
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->
<!-- header start-->

<include file="Public:header"/>

<!-- header end-->
<div class="am-cf admin-main">
 <!-- sidebar start -->
   <include file="Public:menu"/>
  <!-- sidebar end -->

  <!-- content start -->
  <div class="admin-content">
  <input name="yid" value="{$yid}" type="hidden">

    <div class="am-cf am-padding">
      <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">商品管理</strong> / <small>商品列表</small></div>
    </div>
    <div class="am-g">
      <div class="am-u-sm-12 am-u-md-1">
        <div class="am-btn-toolbar">
          <div class="am-btn-group am-btn-group-xs">
            <button type="button" class="am-btn am-btn-default"><span class="am-icon-plus"></span> <a href="{:U('Item/addItem')}">新增商品</a></button>
          </div>
        </div>
      </div>

     <div class="am-u-sm-12 am-u-md-8">
        <div class="am-btn-toolbar">
          <div class="am-btn-group am-btn-group-xs">
          <!--顶级类目-->
            <span >
              <select  id="leim" onchange="javascript:types();">
              <option value=0>顶级类目</option>
              <foreach name="toptype" item="type" key='key'>
              <option value="{$key}">{$type}</option>
              </foreach>
              </select>
            </span>
              <!--二级类目-->
            <span class='typetree' >
              <select name='typeid' id="setype" onchange="javascript:brand();">
              <option value=0>二级类目</option>
              </select>
            </span>
            <!--品牌-->
            <span class='brandtree'>
              <select name='brandid' id="brand">
              <option value=0>全部品牌</option>
              
              </select>
            </span>
            <span> </label>&nbsp;&nbsp; <input type="radio" name="platid" value="0" id="yun" checked="checked">  <label for="yun"> 自有产品</label><input type="radio" name="platid" value="1" id="admin" ><label for="admin">平台产品</label></span>
            <span><button type="button" class="am-btn am-btn-primary am-btn-xs" id="filter">筛选</button></span>
          </div>
        </div>
      </div>

      
      <div class="am-u-sm-12 am-u-md-3">
        <div class="am-input-group am-input-group-sm">
          <input type="text" class="am-form-field" placeholder="输入产品名称 货号" name="keywords" value="{$Think.cookie.keywords}">
          <span class="am-input-group-btn">
             <button class="am-btn am-btn-secondary keyseach" type="button">搜索</button>
          </span>
        </div>
      </div>
    </div>



    <div class="am-g">
      <div class="am-u-sm-12">

          <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
              <tr>
                <th class="table-check"><input type="checkbox" /></th>
                <th class="table-id">ID</th>
                <th class="table-title">商品名称</th>
                <th class="table-title">商品型号</th>
                <th class="table-title">零售价</th>
                <th class="table-title">供货价</th>
                <th class="table-title">库存</th>
                <th class="table-date">生成日期</th>
                <th class="table-date">产品状态</th>
                <th class="table-date"> 隶属于</th>
                <th class="table-set">操作</th>
              </tr>
          </thead>
          <tbody>
            <foreach name="items" item='item'>
            <tr>
              <td><input type="checkbox"/></td>
              <td>{$item['itemid']}</td>
              <td>{$item['itemname']}</td>
              <td>{$item['bn']}</td>
              <td>{$item['price']}</td>
              <td>{$item['supperprice']}</td>
              <td>{$item['inventory']}</td>
              <td>{$item.createtime}</td>
               <if condition="$item['isshen'] eq '已审核'">
              <td>{$item.isshen}</td>
              <else/>
              <td style="color:red">{$item.isshen}</td>
              </if> 
              <if condition="$item['yid'] neq $yid">
              <td>总部直供</td>
              <else/>
              <td></td>
              </if>

              <td>
                <div class="am-btn-toolbar">
                  <div class="am-btn-group am-btn-group-xs">
               
            <if condition="$item['yid'] eq $yid">
                
                   <span class="am-icon-pencil-square-o"></span><a href="{:U('item/editItem',array('itemid'=>$item['itemid']))}">编辑</a>                  
                  <span class="am-icon-trash-o"></span><a href="javascript:void(0)" class="delitem"  value={$item['itemid']}>删除</a> 
              
            
               <if condition="$item['items'] eq 1">
                 <span class="am-icon-cog"></span><a title="确定要下架该产品吗" href="javascript:void(0)" class="downshelves" value="{$item['itemid']}">{$item.itemstatus}</a>
                 <else/>
                    <span class="am-icon-cog"></span><a title="上架该产品吗" href="javascript:void(0)" class="upshelves"  value="{$item['itemid']}">已下架</a>
                 </if>
                </if>
                     <span class="am-icon-eye"></span><a href="{:U('item/viewItem',array('itemid'=>$item['itemid']))}"target="_blank">预览</a>
                  </div>
                </div>
              </td>
            </tr>
            </foreach>
          </tbody>
        </table>
         <!--  <div class="am-cf">
           共 {$pagearr['count']}条记录
         
         <div class="am-fr page"> -->
    <ul class="am-pagination" style="float:right;">
      <li>共<label class="count"> {$pagearr['count']}</label> 条记录</li>
      <li>共<label class="leaf"> {$pagearr['pagetotal']}</label> 页</li>
      
       <li><label>&nbsp;跳转至&nbsp;</label><input type="text" size="2" id="page"  onchange="javascript:setPage();">页</li>
      <li>当前第 <label class="currentpage"> {$pagearr['page']} </label> 页</li>
      <li><a href="javascript:pageajax('firpage')" class="firpage" value="1" >第一页</a></li>
      <li><a href="javascript:pageajax('prepage')" class="prepage" value={$pagearr['page']-1}>上一页</a></li>
      <li><a href="javascript:pageajax('nexpage')" class="nexpage" value={$pagearr['page']+1}>下一页</a></li>
      <li><a href="javascript:pageajax('laspage')" class="laspage" value={$pagearr['pagetotal']}>最末页</a></li>
    </ul>
  </div>

</div>

      </div>

    </div>
  </div>
  <!-- content end -->
</div>
<include file="Public:footer"/>
 <footer>
  <hr>
  <p class="am-padding-left">© 2014 商之联.</p>
</footer>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}polyfill/rem.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}polyfill/respond.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}amazeui.legacy.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="{:C('SUPPLIER_ADMIN_JS')}jquery.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}amazeui.min.js"></script>
<!--<![endif]-->
<script src="{:C('SUPPLIER_ADMIN_JS')}app.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}jquery.cookie.js"></script>
<script type="text/javascript">

/////产品上架
 $(document).on('click','.upshelves',function(){
   var itemid=$(this).attr('value');

   $.ajax({
            type:"GET",
            data:{"itemid":itemid},
            url: "{:U('Item/upshelves' )}",
            dataType:"json",
            success:function(data){
                if (data==2)
                {
                    alert("该产品上架成功");
                    
                 }if(data==3)
                 {
                  alert("产品未审核");
                 }
                }


          });


 })
///下架产品
$(document).on('click','.downshelves',function()
{
  
  var itemid=$(this).attr('value');
   $.ajax({
            type:"GET",
            data:{"itemid":itemid},
            url: "{:U('Item/down' )}",
            dataType:"json",
            success:function(data){
                if (data==2)
                {
                    alert("未知错误");
                    
                 }
                 if(data==3)
                 {
                  alert("商品下架成功");
                 }
                }


          });


})

</script>
<script type="text/javascript">
//ajax 动态生成的元素绑定事件
   $(document).on('click','.delitem',function(){
        var res=confirm("确定删除");
        if(!res){
          return false;
        }
        var id=$(this).attr('value');
        $.ajax( {
            type:"GET",
            data:{"itemid":id},
            url: "{:U('Item/delItem','')}",
            dataType:"json",
            success:function(message){
                if (message.status)
                {
                    alert(message.msg);
                    location.reload();
                 }else{
                 alert(message.msg);
                  location.reload();
                }
                }


          })
   })
//ajax 添加类目
$(function()
{
  $.ajax({
    type:'GET',
    url:"{:U('Item/Type2Brand')}",
    dataType:"json",
    success:function(message){
      $('.typetree select').append(message.string);
     // $('.brandtree select').append(message.bsting);
    }
  });
})
//类目 品牌联动
var getBrand=function(typeid){
  var typeid = arguments[0]?arguments[0] : 1;
  $.ajax({
    type:'GET',
    url:"{:U('Item/getBrand')}",
    data:{"typeid":typeid},
    dataType:"json",
    success:function(message){

      $('.brandtree select ').append(message);
     // $('.brandtree select *').replaceWith(message);
    }
  });
}

$(function(){
  $("select[name='typeid']").change(function(){
  var typeid=$("select[name='typeid'] option:selected").val();

   $('.brandtree select option').remove();
    getBrand(typeid);

  });
});

//筛选条件
  //公用ajax 晒需条件
  var searchitem=function(page,keywords){

     //获取搜索条件
     var page = arguments[0]?arguments[0] : 1;
     var keywords=arguments[1]?arguments[1] : '';
     var $typeid=$("select[name='typeid'] option:selected").val();
     var $brandid=$("select[name='brandid'] option:selected").val();
    var yid= $("input[name='yid']").val();
   var $platid=$("input[name='platid']:checked").val();
    

    /* var  $ally=$("#ally").val();//盟友*/
   
     $.ajax({
        type:'POST',
        url:"{:U('Item/getItem')}",
        data:{"typeid":$typeid,"brandid":$brandid,"page":page,"keywords":keywords,"platid":$platid},
        dataType:"json",
        success:function(message){
         //解析json 数据
           if(message.status){
              var $page=message.pagearr; //底部分页
              var $items=message.item;//订单
              var $tbody=$('<tbody></tbody>');
              var $string='';
              $.each($items,function(key,item){
                  $string+="<tr>";
                  $string+='<td><input type="checkbox"></td>';
                  $string+="<td>"+item.itemid+"</td>";
                  $string+="<td>"+item.itemname+"</td>";
                  $string+="<td>"+item.bn+"</td>";
                  $string+="<td>"+item.price+"</td>";
                  $string+="<td>"+item.supperprice+"</td>";
                  $string+="<td>"+item.inventory+"</td>";
                  $string+="<td>"+item.createtime+"</td>";
                  if(item.isshen=='已审核'){
                  $string+="<td>"+item.isshen+"</td>";
                }else{
                  $string+='<td style="color:red">'+item.isshen+"</td>";

                }
                if(item.yid==yid){
                     $string+="<td></td>";

                  }else{
                     
                      $string+="<td>总部直供</td>";

                  }
                  
                  $string+='<td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">';
                
                  if(item.yid==yid)
                  {
                  $string+='<span class="am-icon-pencil-square-o"></span><a href=__URL__/editItem?itemid='+item.itemid+'>编辑</a>';
                  $string+='<span class=am-icon-trash-o></span><a href="javascript:void(0)" class="delitem" value='+item.itemid+'> 删除 </a>';
                  if(item.items==1)
                    {
                    $string+='<span class=am-icon-cog></span><a title="确定要下架该产品吗" href="javascript:void(0)" class="downshelves" value='+item.itemid+'>已上架</a>';
                  } else
                  {
                    $string+='<span class=am-icon-cog></span><a title="上架该产品" href="javascript:void(0)" class="upshelves" value='+item.itemid+'> 已下架</a>';

                  }

                 
              }
                  

                  
                
                
                  $string+='<span class=am-icon-eye></span><a href=viewItem?itemid='+item.itemid+'  target="_blank">预览</a>';
                  $string+="</div></div></td></tr>"; 
              });
              $tbody.append($string);
              $($tbody).replaceAll("tbody");
              //替换分页
              $(".count").html($page.count);
              $(".leaf").html($page.pagetotal);
              $(".currentpage").html($page.page);
              $("#pagesize").val($page.pagesize);
              $('.prepage').attr('value',$page.prevpage);
              $('.nexpage').attr('value', $page.nextpage);
              $('.laspage').attr('value',$page.pagetotal);

           }else{
               $('tbody').html('暂无数据');
           }
        }

         });
    }

  
   //筛选数据
  $("#filter").click(function(){
      searchitem();
  })
  //翻页事件
  function pageajax(name){
     var pagevalue=$('.'+name).attr('value');
     var keywords=$("input[name='keywords']").val();
     searchitem(pagevalue,keywords);
     return false;
  }

$(function(){
  $('.keyseach').click(function(){
    var keywords=$("input[name='keywords']").val();
     searchitem(1,keywords);
     return false;
  });
})


function setPage(){
  var page=$("#page").val();
     var keywords=$("input[name='keywords']").val();
    searchitem(page,keywords);
     return false;


}
</script>
<script type="text/javascript">
//获取二级类目
  function types(){
    var top=$('#leim').val();
    jQuery.get('{:U("Item/stype")}',
      {typeid:top,},
      function(data){
        $('#setype option').remove("option[value !=0]");
 $('#setype').append(data); 

      },'text');
  }

  //获取对应的品牌
  function brand(){
    var brand=$('#setype').val();
      jQuery.get('{:U("Item/brand")}',
        {brandid:brand,},
        function(data){
           $('#brand option').remove("option[value !=0]");
          $('#brand').append(data); 
        },'text');
  }
</script>
<script type="text/javascript">
  $(function(){
       var modultname="Item";

       $('.'+modultname).addClass('am-in');
});
</script>
</body>
</html>
